/**
 * jQuery-based
 *
 * @author Bevis.Zhao
 */
(function(){
	var data = {
		shadowID : 'animateTo_shadow',
		shadowHTML : '<div id="animateTo_shadow" style="display: none;' + 
			'background-color: #ddd; border: solid 1px darkgray; position: static; top: 0px; z-index: 100000;"/>'
	};
	
	jQuery.fn.animateTo = function(target, callback, options){
		$.extend({duration : 300}, options);
	    var self = this;
	    var target = $(target);
		
	    shadow = $('#' + data.shadowID);
	    if (shadow.length == 0)
	        $('body').prepend(shadow = $(data.shadowHTML));
	    else if (shadow.is(':animated')) 
	        return;
		
		shadow.css({
				width : self.width(), height : self.height(), top :  self.offset().top,
				left : self.offset().left, opacity : 0.5, position : 'absolute'
			}).animate({
			        width: target.innerWidth(), height: target.innerHeight(),
			        top: target.offset().top, left: target.offset().left
				}, options
			).animate({ opacity: 0}, {
				duration: 100, complete: function(){
					shadow.hide();
					if(typeof callback == 'function')
						callback.call(shadow, self, target);
				}
			});	
	};
	jQuery.animateTo = function(from, target, callback, options){
			$(from).animateTo(target, callback, options);
	};
	
})();
